<?php
/*
 * @Author: your name
 * @Date: 2021-11-02 20:43:06
 * @LastEditTime: 2022-02-28 11:48:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \property\app\Http\Controllers\admin_controller\BaseController.php
 */

namespace App\Http\Controllers\crm;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Request;


class BaseController extends Controller
{
    


    /**
     * @description: 返回参数
     * @param int    $code       状态码
     * @param string $msg        返回信息
     * @param array  $data       参数
     * @param int    $trueCode   真状态码
     * @return 
     */
    protected function create($code, $msg = '', $data = [], $trueCode = 200)
    {
        $result = [
            'code' => $code,
            'message' => $msg,
            'data' => $data
        ];
        // if (isset($_POST['HTTP_SERVER'])) {
            $_POST['HTTP_SERVER']->status($trueCode);
            return response($result);
        // } else {
            // return response($result, $trueCode);
        // }
    }


    protected function getAdminId()
    {
        $redisKey    =  CRM_LOGIN_REDIS_KEY;
        $headerKey   =  CRM_LOGIN_HEADER_KEY;
        $token = $_SERVER[$headerKey];
        return \App\Http\Controllers\redis\RedisController::redisGet($redisKey . $token, ['RedisDB' => 11]);
    }

    protected function getAdminInfo($field = false)
    {
        $userId = $this->getAdminId();
        return redis_mysql_selone_return('admins', $userId, $field);
    }

  



    static function __callStatic($methodName, $arguments){
        $className = __CLASS__;
        $className = new  $className();
        return call_user_func_array([$className, substr( $methodName,0,-1 )], $arguments);
    }
    
}
